package yinxiang;


import com.evernote.auth.EvernoteAuth;
import com.evernote.auth.EvernoteService;
import com.evernote.clients.ClientFactory;
import com.evernote.clients.NoteStoreClient;
import com.evernote.clients.UserStoreClient;
import com.evernote.edam.error.EDAMSystemException;
import com.evernote.edam.error.EDAMUserException;
import com.evernote.thrift.TException;
import com.evernote.thrift.transport.TTransportException;

/****
 * 个人印象笔记配置
 */
public class Config {

    private static UserStoreClient userStore;

    private static NoteStoreClient noteStore;

    //印象笔记个人开发者临时token https://dev.yinxiang.com/doc/articles/authentication.php#devtoken 过期可重新获取
    private static final String AUTH_TOKEN = "S=s30:U=1a8b3ba:E=189fde2188d:C=189d9d59300:P=1cd:A=en-devtoken:V=2:H=11a8651d57bc9152cc2664179003eca5";

    static {
        // Set up the UserStore client and check that we can speak to the server
        EvernoteAuth evernoteAuth = new EvernoteAuth(EvernoteService.YINXIANG, AUTH_TOKEN);
        ClientFactory factory = new ClientFactory(evernoteAuth);
        try {
            userStore = factory.createUserStoreClient();
        } catch (TTransportException e) {
            e.printStackTrace();
        }

        boolean versionOk = false;
        try {
            versionOk = userStore.checkVersion("Evernote EDAMDemo (Java)",
                    com.evernote.edam.userstore.Constants.EDAM_VERSION_MAJOR,
                    com.evernote.edam.userstore.Constants.EDAM_VERSION_MINOR);
        } catch (TException e) {
            e.printStackTrace();
        }
        if (!versionOk) {
            System.err.println("Incompatible Evernote client protocol version");
            System.exit(1);
        }
        // Set up the NoteStore client
        try {
            noteStore = factory.createNoteStoreClient();
        } catch (EDAMUserException e) {
            e.printStackTrace();
        } catch (EDAMSystemException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        }
    }

    public static NoteStoreClient getNoteStore() {
        return noteStore;
    }

    public static UserStoreClient getUserStore() {
        return userStore;
    }
}
